<template>
  <div class="wh-100 p-8">
    <div class="wh-100 overflow-auto" style="background-color: white">
      <div class="w-100   d-flex-between-center pl-16 pr-16 bor-base-b head-box">
        <div class="fs-14 fw-6">毕业去向审核</div>
        <Button @click="$router.go(-1)" style="background-color: white">返回</Button>
      </div>

      <div class="w-100   pl-32 ch85">
        <div class="w-100 h-25  bor-base-b mt-8">
          <Form ref="form" class="w-50" :model="form" :label-width="quryLabelWidth">
            <FormItem class="small" label="学号" prop="xh">
              <Input maxlength="100" v-model="form.xh" disabled />
            </FormItem>
            <FormItem class="small" label="姓名" prop="name">
              <Input maxlength="100" v-model="form.name" disabled />
            </FormItem>
            <FormItem class="small" label="所在院系" prop="yxmc">
              <Input maxlength="100" v-model="form.yxmc" disabled />
            </FormItem>
            <FormItem class="small" label="专业" prop="zy">
              <Input maxlength="100" v-model="form.zy" disabled />
            </FormItem>
            <FormItem class="small" label="班级" prop="szbj">
              <Input maxlength="100" v-model="form.szbj" disabled />
            </FormItem>
          </Form>
        </div>
        <div class="w-100 h-auto pt-8 bor-base-b pb-12">
          <Form ref="qxForm" class="w-100" :model="qxform" :label-width="quryLabelWidth2">
            <div class="w-100 d-flex-align-center">
              <FormItem class="small w-50" label="就业状况" prop="onetype"
                        :rules="{ required: true, message: '不能为空', trigger: 'change' }">
                <Select
                    @on-change="chooseOneType"
                    v-model="qxform.onetype"
                    clearable
                    transfer
                    :disabled="type == '2' || type == '3' || type == '4' || form.pyfs_code == '21' || form.pyfs_code == '41'"
                >
                  <Option v-for="item in oneTypeDicts" :value="item.value">{{ item.title }}</Option>
                </Select>
              </FormItem>
              <div class="w-50 h-100 d-flex-align-center px-20 ">
                <Alert type="error" show-icon>若所选毕业去向类型与要上传的就业证明材料不符，请重新去向类型并选填</Alert>
              </div>
            </div>

            <FormItem class="small w-50" label="就业类别" prop="type" :rules="{ required: true, message: '不能为空' }">
              <el-cascader
                  style="width: 100%"
                  :show-all-levels="false"
                  v-model="qxform.type"
                  size="small"
                  :options="bysqxDicts"
                  :props="props"
                  :empty="'暂无数据'"
                  clearable
                  :disabled="type == '2' || type == '3' || type == '4' || form.pyfs_code == '21' || form.pyfs_code == '41'"
              >
                <template slot-scope="{ node, data }">
                  <span>{{ data.title }}</span>
                </template>
              </el-cascader>
            </FormItem>
            <div class="w-100 d-flex-align-center" v-if="qxformIsShow.dwmc">
              <FormItem class="small w-50" :label="nameOfOrganizationLabel" prop="dwmc"
                        :rules="[{ required: qxformRequired.dwmc, message: '不能为空', trigger: 'blur' }]">
                <Input maxlength="100" v-model="qxform.dwmc" clearable :placeholder="qxformPlaceholder.dwmc" />
              </FormItem>

              <a class="cursor-pointer ml-8 mr-8" :href="'https://www.tianyancha.com/search?key=' + qxform.dwmc"
                 target="_blank">天眼查</a>
              <a class="cursor-pointer ml-8 mr-8" href="javascript:;" @click="storageApply">单位信息申请入驻省库 </a>
            </div>
            <FormItem v-if="qxformIsShow.major" class="small w-50" label="升学专业" prop="major"
                      :rules="[{ required: qxformRequired.major, message: '该项必填', trigger: 'blur' }]">
              <Input v-model="qxform.major" placeholder="请输入所学专业" />
            </FormItem>


            <!--                  <FormItem label="统一社会信用代码" prop="tyshxycode">-->
            <FormItem
                v-if="qxformIsShow.tyshxycode"
                class="small w-50"
                label="统一社会信用代码"
                prop="tyshxycode"
                :rules="[{ required: qxformRequired.tyshxycode, trigger: 'blur', validator: validateOrganizingInstitutionBarCode }]"
            >
              <Input maxlength="18" v-model="qxform.tyshxycode" clearable />
            </FormItem>

            <FormItem v-if="qxformIsShow.dwxz" class="small w-50" label="单位性质" prop="dwxz"
                      :rules="[{ required: qxformRequired.dwxz, message: '不能为空', trigger: 'change' }]">
              <Select v-model="qxform.dwxz" clearable transfer>
                <Option v-for="item in unitNatureDicts" :value="item.value">{{ item.title }}</Option>
              </Select>
              <!--                      <Input maxlength="100" v-model="qxform.dwxz" clearable />-->
            </FormItem>

            <!--                  <FormItem label="单位行业" prop="dwhy">-->
            <FormItem v-if="qxformIsShow.dwhy" class="small w-50" label="单位行业" prop="dwhy"
                      :rules="[{ required: qxformRequired.dwhy, message: '不能为空', trigger: 'change' }]">
              <Select v-model="qxform.dwhy" clearable transfer>
                <Option v-for="item in unitIndustryDicts" :value="item.value">{{ item.title }}</Option>
              </Select>
              <!--                      <Input maxlength="100" v-model="qxform.dwhy" clearable />-->
            </FormItem>
            <!--{{qxform.dwszd}}-->
            <FormItem
                v-if="qxformIsShow.dwszd"
                class="small w-50"
                :label="locationOfTheUnitLabel"
                prop="dwszd"
                :rules="[{ required: qxformRequired.dwszd, trigger: 'change', validator: validatelocationOfTheUnit }]"
            >
              <!--                        <Input maxlength="100" v-model="qxform.dwszd" clearable :readonly="type=='2'||type=='3'||type=='4'"/>-->
              <!--                        <Select maxlength="100" v-model="qxform.dwszd" clearable :readonly="type=='2'||type=='3'||type=='4'">-->
              <!--                          <Option v-for="item in dqCodeList" :value="item.code">{{item.displayName}}</Option>-->
              <!--                        </Select>-->
              <!--<Cascader :data="areaCodeList" v-model="areaNodes"></Cascader>-->
              <!--<el-cascader class="w-100" :props="provincesAndMunicipalitiesProps" v-model="qxform.dwszd" :options="areaCodeList"></el-cascader>-->
              <Cascader class="w-100" :data="areaCodeList" v-model="qxform.dwszd" :props="provincesAndMunicipalitiesProps"></Cascader>
            </FormItem>

            <!--                  <FormItem label="工作职位类别" prop="gzzwlb">-->
            <FormItem v-if="qxformIsShow.gzzwlb" class="small w-50" label="工作职位类别" prop="gzzwlb"
                      :rules="[{ required: qxformRequired.gzzwlb, message: '不能为空', trigger: 'change' }]">
              <Select v-model="qxform.gzzwlb" clearable transfer>
                <Option v-for="item in jobPositionCategoryDicts" :value="item.value">{{ item.title }}</Option>
              </Select>
              <!--                      <Input maxlength="100" v-model="qxform.gzzwlb" clearable />-->
            </FormItem>

            <FormItem v-if="qxformIsShow.dwlxr" class="small w-50" label="单位联系人" prop="dwlxr"
                      :rules="[{ required: qxformRequired.dwlxr, message: '不能为空', trigger: 'blur' }]">
              <Input maxlength="100" v-model="qxform.dwlxr" clearable />
            </FormItem>

            <FormItem
                v-if="qxformIsShow.lxrdw"
                class="small w-50"
                label="联系人电话"
                prop="lxrdw"
                :rules="[
                                            { required: qxformRequired.lxrdw, message: '该项必填', trigger: 'blur' },
                                            { pattern: /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/, message: '请输入正确的联系人电话,如021-88888888' }
                                        ]"
            >
              <Input maxlength="100" v-model="qxform.lxrdw" clearable />
            </FormItem>

            <FormItem
                v-if="qxformIsShow.dwdh"
                class="small w-50"
                label="联系人手机"
                prop="dwdh"
                :rules="[{ pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/, message: '请输入正确的手机号，如13988888888' }]"
            >
              <Input maxlength="100" v-model="qxform.dwdh" clearable />
            </FormItem>

            <FormItem
                v-if="qxformIsShow.lxremail"
                class="small w-50"
                label="联系人Email"
                prop="lxremail"
                :rules="[
                                            { required: qxformRequired.lxremail, message: '该项必填', trigger: 'blur' },
                                            { pattern: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, message: '请输入正确的Email地址' }
                                        ]"
            >
              <Input maxlength="100" v-model="qxform.lxremail" clearable />
            </FormItem>

            <FormItem v-if="qxformIsShow.lxrfax" class="small w-50" label="联系人传真" prop="lxrfax">
              <Input maxlength="100" v-model="qxform.lxrfax" clearable />
            </FormItem>

            <FormItem v-if="qxformIsShow.dwdz" class="small w-50" label="单位地址" prop="dwdz"
                      :rules="{ required: false }">
              <Input maxlength="100" v-model="qxform.dwdz" clearable />
            </FormItem>

            <FormItem
                v-if="qxformIsShow.dwyb"
                class="small w-50"
                label="单位邮编"
                prop="dwyb"
                :rules="[
                                            { required: qxformRequired.dwyb, message: '该项必填', trigger: 'blur' },
                                            { pattern: /[1-9]\d{5}(?!\d)/, message: '请输入正确的邮政编码' }
                                        ]"
            >
              <Input maxlength="100" v-model="qxform.dwyb" clearable />
            </FormItem>

            <FormItem v-if="qxformIsShow.zzhxz" class="small w-50" label="月薪（税前）" prop="zzhxz"
                      :rules="[{ pattern: /^(0|[1-9][0-9]*)$/, message: '请输入非负数字' }]">
              <Input maxlength="100" v-model="qxform.zzhxz" clearable />
            </FormItem>

            <FormItem v-if="qxformIsShow.enterpriseSize" class="small w-50" label="企业规模" prop="enterpriseSize"
                      :rules="[{ required: qxformRequired.enterpriseSize, message: '该项必填', trigger: 'blur' }]">
              <Input v-model="qxform.enterpriseSize" placeholder="请输入企业规模多少人" />
            </FormItem>

            <FormItem v-if="qxformIsShow.enterpriseRevenue" class="small w-50" label="企业营收" prop="enterpriseRevenue"
                      :rules="[{ required: qxformRequired.enterpriseRevenue, message: '该项必填', trigger: 'blur' }]">
              <Input v-model="qxform.enterpriseRevenue" placeholder="请输入企业营收多少元/月" />
            </FormItem>

            <FormItem
                v-if="qxformIsShow.isBaseEmployment"
                class="small w-50"
                label="是否基层就业"
                prop="isBaseEmployment"
                :rules="{ required: qxformRequired.isBaseEmployment, message: '请选择是否基层就业', trigger: 'change', validator: validateBaseLevelOrNot }"
            >
              <RadioGroup v-model="qxform.isBaseEmployment">
                <Radio :label="true">
                  <span>是</span>
                </Radio>
                <Radio :label="false">
                  <span>否</span>
                </Radio>
              </RadioGroup>
            </FormItem>

            <FormItem v-if="qxformIsShow.jwxxzwmc" class="small w-50" label="留学院校中文名称" prop="jwxxzwmc"
                      :rules="[{ required: qxformRequired.jwxxzwmc, message: '该项必填', trigger: 'change' }]">
              <Select
                  @on-change="fillForeignName"
                  v-model="qxform.jwxxzwmc"
                  clearable
                  filterable
                  :disabled="type == '2' || type == '3' || type == '4' || form.pyfs_code == '21' || form.pyfs_code == '41'"
              >
                <Option v-for="item in gwSchoolCodeList" :value="item.chineseName">{{ item.chineseName }}</Option>
              </Select>
            </FormItem>

            <FormItem v-if="qxformIsShow.jwxxwwmc" class="small w-50" label="留学院校外文名称" prop="jwxxwwmc"
                      :rules="[{ required: qxformRequired.jwxxwwmc, message: '该项必填', trigger: 'blur' }]">
              <!--                      <Select @on-change="fillChineseName" v-model="qxform.jwxxwwmc" clearable  :disabled="type=='2'||type=='3'||type=='4'||form.pyfs_code=='21'||form.pyfs_code=='41'">-->
              <!--                        <Option v-for="item in gwSchoolCodeList" :value="item.foreignName">{{ item.foreignName }}</Option>-->
              <!--                      </Select>-->
              <Input v-model="qxform.jwxxwwmc" placeholder="请输入留学院校外文名称" />
            </FormItem>

            <FormItem v-if="qxformIsShow.lxgjdq" class="small w-50" label="留学国家/地区" prop="lxgjdq"
                      :rules="[{ required: qxformRequired.lxgjdq, message: '该项必填', trigger: 'blur' }]">
              <Input v-model="qxform.lxgjdq" placeholder="请输入留学国家/地区" />
            </FormItem>

            <FormItem v-if="qxformIsShow.lxzyzwmc" class="small w-50" label="留学专业中文名称" prop="lxzyzwmc"
                      :rules="[{ required: qxformRequired.lxzyzwmc, message: '该项必填', trigger: 'blur' }]">
              <Input
                  maxlength="100"
                  v-model="qxform.lxzyzwmc"
                  clearable
                  :disabled="type == '2' || type == '3' || type == '4' || form.pyfs_code == '21' || form.pyfs_code == '41'"
              />
            </FormItem>


            <FormItem v-if="qxformIsShow.lxzywwmc" class="small w-50" label="留学专业外文名称" prop="lxzywwmc"
                      :rules="[{ required: qxformRequired.lxzywwmc, message: '该项必填', trigger: 'blur' }]">
              <Input
                  maxlength="100"
                  v-model="qxform.lxzywwmc"
                  clearable
                  :disabled="type == '2' || type == '3' || type == '4' || form.pyfs_code == '21' || form.pyfs_code == '41'"
              />
            </FormItem>

            <FormItem v-if="qxformIsShow.lxxl" class="small w-50" label="留学学历" prop="lxxl"
                      :rules="[{ required: qxformRequired.lxxl, message: '该项必填', trigger: 'change' }]">
              <Select v-model="qxform.lxxl" clearable
                      :disabled="type == '2' || type == '3' || type == '4' || form.pyfs_code == '21' || form.pyfs_code == '41'">
                <Option value="专科">专科</Option>
                <Option value="本科">本科</Option>
                <Option value="硕士">硕士</Option>
                <Option value="博士">博士</Option>
              </Select>
            </FormItem>

            <FormItem v-if="qxformIsShow.zmcl" class="small" label="证明材料" prop="zmcl"
                      :rules="[{ required: qxformRequired.zmcl, trigger: 'change', validator: validateEvidentiaryMaterial }]">
              <uploadPicture :images="backImages" ref="supportingMaterialRef" :max-count="5"></uploadPicture>
            </FormItem>
            <div class="cfont12" style="color: rgb(153, 153, 153);">
              签协议就业请上传协议书附件； 签劳动合同就业请上传劳动合同附件； 有单位用人证明，请上传单位用人证明附件；升学请提供录取通知书附件；
              出国、出境请提供出国护照附件
            </div>

          </Form>
        </div>
        <div v-if="showPassBtn" class="w-100 h-30 d-flex pt-24">
          <div class="w-30 h-auto ">
            <Form ref="shform" :model="shform" :label-width="labelWidth85">
              <FormItem label="审核意见" prop="reason">
                <Input type="textarea" v-model="shform.comment" :rows="4" />
              </FormItem>
              <FormItem label="消息通知">
                <Checkbox v-model="shform.sendMessage">站内消息通知</Checkbox>
              </FormItem>
              <Button type="primary" class="cml25" :loading="passLoading" @click="passTask">通过</Button>
              <!--              <Button type="error" :loading="noPassLoading" @click="noPassTask">不通过</Button>-->
              <Button type="warning" :loading="backLoading" @click="backTask">驳回至学生</Button>
              <Button v-if="showButton"  type="error" :loading="backCollegeLoading" @click="backCollegeTask">驳回至学院</Button>
            </Form>
          </div>
          <!-- 警告提示-->
          <div class="fs-12 ml-8 cw630">
            <Alert show-icon>
              <div>
                通过：如学生填写的毕业去向与就业证明材料一致，字段上报填写完整，审核无误可通过。
              </div>
              <div>
                驳回：如毕业生填写的毕业去向与就业证明材料一致，部分字段信息填写与实际情况不一致，请填写驳回修改意见，学生填报信息将会保留，学生可在原有填写去向基础上修改后再次提交。
              </div>
            </Alert>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
// 20230918
import { pass, noPass, back, backCollege, showButton, awaitAdd } from '@/api/activiti';
// 20230918
import uploadPicThumb from '../../../components/uploadPicture/uploadPicture.vue';
import { getDictDataByType } from '@/api/index.js';
import { getAreaTreeNodes } from '@/libs/areaData';
import { addJyqxInfo, editJyqxInfo, editAndApplyJyqxInfo } from '@/api/bys/jyqx/jyqx.js';
import { getAllGwschoolCodeList, getGwschoolCodeList } from '@/api/gwschoolCode';
import { newProvincialDataApi, obtainEmploymentStatusDataAPI } from '@/api/bys/index.js';
// import Cookies from "_js-cookie@2.2.1@js-cookie";
import crypto from '@/libs/secret';
import { imageUploadDataApi, provincialDataApi } from '../../../api/bys';
import UploadPicture from '../../../components/uploadPicture/uploadPicture.vue';
import { judgmentRequired, updateVal } from '@/util/ObjectUtil';
import { saveOrUpdate } from '../../../api/bys/jyqx/jyqx';

let backImages = null;

export default {
  name: 'user',
  components: {
    UploadPicture,
    uploadPicThumb
  },
  props: {
    dataValue: {
      type: Object,
      default() {
        return {};
      }
    },
    type: {
      type: String,
      default() {
        return '';
      }
    },
    isZf: {
      type: String,
      default() {
        return '0';
      }
    }
  },
  //20230921
  computed: {
    required: function() {
      return this.qxform.onetype == 'notEmployed' ? false : true;
    }
  },
  //20230921
  data() {
    return {
      validatelocationOfTheUnit: (rule, value, callback) => {
        if (this.qxformRequired.dwszd) {
          if (this.qxform.dwszd === null || this.qxform.dwszd === '') {
            callback(new Error('请选择单位所在地'));
          } else {
            callback();
          }
        } else {
          callback();
        }
      },
      validateOrganizingInstitutionBarCode: (rule, value, callback) => {
        if (this.qxformRequired.tyshxycode) {
          const result = this.verify(this.qxform.tyshxycode);
          if (result) {
            callback();
          } else {
            callback(new Error('请输入正确得组织机构代码'));
          }
        } else {
          callback();
        }
      },
      validateBaseLevelOrNot: (rule, value, callback) => {
        if (this.qxformRequired.isBaseEmployment) {
          if (this.qxform.isBaseEmployment === null) {
            callback(new Error('请选择是否基层就业'));
          } else {
            callback();
          }
        } else {
          callback();
        }
      },
      validateEvidentiaryMaterial: (rule, value, callback) => {
        if (this.qxformRequired.zmcl) {
          if (this.$refs.supportingMaterialRef.formFile.length > 0) {
            callback();
          } else {
            callback(new Error('请上传证明材料'));
          }
        } else {
          callback();
        }
      },
      quryLabelWidth: 120,
      quryLabelWidth2: 140,
      labelWidth85: 85,
      dqCodeList: [], //地区代码表
      // 20230918
      shform: {
        sendMessage: true
      },
      gwSchoolCodeList: [],
      passLoading: false,
      noPassLoading: false,
      backLoading: false,
      backCollegeLoading: false,
      areaCodeList: [], //地区代码表
      // 20230918
      editLoading: false,
      editAndApplyLoading: false,
      type: 0,
      // procDefId:"bysJysbApply",//工作流
      submitLoading: false,
      value: ['1', '2'],
      // sfsTypes:[],
      // sydTypes:[],
      // xlccs:[],
      bysqxDicts: [],
      qxform: {
        onetype: '', // 就业状况
        type: [], // 就业类别 当前选中的每级value
        dwmc: '', // 单位名称
        tyshxycode: '', // 组织机构代码
        dwxz: '', // 单位性质
        dwhy: '', // 单位行业
        dwszd: [], // 单位所在地
        gzzwlb: '', // 工作职位类别
        dwlxr: '', // 单位联系人
        lxrdw: '', // 单位联系人电话
        dwdh: '', // 联系人手机
        lxrfax: '', // 联系人传真
        dwdz: '', // 单位地址
        dwyb: '', // 单位邮编
        zzhxz: '', // 工资收入
        lxremail: '', //联系人Email
        extendWord1: '', // 扩充字段1
        extendWord2: '', // 扩充字段2
        extendWord3: '', // 扩充字段3
        extendWord4: '', // 扩充字段4
        extendWord5: '', // 扩充字段5
        zmcl: '', //证明材料
        isBaseEmployment: null, // 是否基层就业
        enterpriseSize: '', // 企业规模
        enterpriseRevenue: '', // 企业营收
        major: '', // 升学专业
        lxgjdq: '', // 留学国家/地区
        jwxxzwmc: '', //  学校中文名称
        jwxxwwmc: '', // 学校外文名称
        lxzyzwmc: '', // 留学专业中文名称
        lxzywwmc: '', // 留学专业外文名称
        lxxl: '' // 留学学历
      },
      qxformRequired: {
        onetype: false, // 就业状况
        type: false, // 就业类别 当前选中的每级value
        dwmc: false, // 单位名称
        tyshxycode: false, // 组织机构代码
        dwxz: false, // 单位性质
        dwhy: false, // 单位行业
        dwszd: false, // 单位所在地
        gzzwlb: false, // 工作职位类别
        dwlxr: false, // 单位联系人
        lxrdw: false, // 单位联系人电话
        dwdh: false, // 联系人手机
        lxrfax: false, // 联系人传真
        dwdz: false, // 单位地址
        dwyb: false, // 单位邮编
        zzhxz: false, // 工资收入
        lxremail: false, //联系人Email
        extendWord1: false, // 扩充字段1
        extendWord2: false, // 扩充字段2
        extendWord3: false, // 扩充字段3
        extendWord4: false, // 扩充字段4
        extendWord5: false, // 扩充字段5
        zmcl: false, //证明材料
        isBaseEmployment: false, // 是否基层就业
        enterpriseSize: false, // 企业规模
        enterpriseRevenue: false, // 企业营收
        major: false, // 升学专业
        lxgjdq: false, // 留学国家/地区
        jwxxzwmc: false, //  学校中文名称
        jwxxwwmc: false, // 学校外文名称
        lxzyzwmc: false, // 留学专业中文名称
        lxzywwmc: false, // 留学专业外文名称
        lxxl: false // 留学学历
      },
      qxformPlaceholder: {
        onetype: '请选择或输入', // 就业状况
        type: '请选择或输入', // 就业类别 当前选中的每级value
        dwmc: '请选择或输入', // 单位名称
        tyshxycode: '请选择或输入', // 组织机构代码
        dwxz: '请选择或输入', // 单位性质
        dwhy: '请选择或输入', // 单位行业
        dwszd: '请选择或输入', // 单位所在地
        gzzwlb: '请选择或输入', // 工作职位类别
        dwlxr: '请选择或输入', // 单位联系人
        lxrdw: '请选择或输入', // 单位联系人电话
        dwdh: '请选择或输入', // 联系人手机
        lxrfax: '请选择或输入', // 联系人传真
        dwdz: '请选择或输入', // 单位地址
        dwyb: '请选择或输入', // 单位邮编
        zzhxz: '请选择或输入', // 工资收入
        lxremail: '请选择或输入', //联系人Email
        extendWord1: '请选择或输入', // 扩充字段1
        extendWord2: '请选择或输入', // 扩充字段2
        extendWord3: '请选择或输入', // 扩充字段3
        extendWord4: '请选择或输入', // 扩充字段4
        extendWord5: '请选择或输入', // 扩充字段5
        zmcl: '请选择或输入', //证明材料
        isBaseEmployment: '请选择或输入', // 是否基层就业
        enterpriseSize: '请选择或输入', // 企业规模
        enterpriseRevenue: '请选择或输入', // 企业营收
        major: '请选择或输入', // 升学专业
        lxgjdq: '请选择或输入', // 留学国家/地区
        jwxxzwmc: '请选择或输入', //  学校中文名称
        jwxxwwmc: '请选择或输入', // 学校外文名称
        lxzyzwmc: '请选择或输入', // 留学专业中文名称
        lxzywwmc: '请选择或输入', // 留学专业外文名称
        lxxl: '请选择或输入' // 留学学历
      },
      qxformIsShow: {
        onetype: false, // 就业状况
        type: false, // 就业类别 当前选中的每级value
        dwmc: false, // 单位名称
        tyshxycode: false, // 组织机构代码
        dwxz: false, // 单位性质
        dwhy: false, // 单位行业
        dwszd: false, // 单位所在地
        gzzwlb: false, // 工作职位类别
        dwlxr: false, // 单位联系人
        lxrdw: false, // 单位联系人电话
        dwdh: false, // 联系人手机
        lxrfax: false, // 联系人传真
        dwdz: false, // 单位地址
        dwyb: false, // 单位邮编
        zzhxz: false, // 工资收入
        lxremail: false, //联系人Email
        extendWord1: false, // 扩充字段1
        extendWord2: false, // 扩充字段2
        extendWord3: false, // 扩充字段3
        extendWord4: false, // 扩充字段4
        extendWord5: false, // 扩充字段5
        zmcl: false, //证明材料
        isBaseEmployment: false, // 是否基层就业
        enterpriseSize: false, // 企业规模
        enterpriseRevenue: false, // 企业营收
        major: false, // 升学专业
        lxgjdq: false, // 留学国家/地区
        jwxxzwmc: false, //  学校中文名称
        jwxxwwmc: false, // 学校外文名称
        lxzyzwmc: false, // 留学专业中文名称
        lxzywwmc: false, // 留学专业外文名称
        lxxl: false // 留学学历
      },
      form: {},
      backRoute: '',
      procDefId: '',
      unitIndustryDicts: [],
      unitNatureDicts: [],
      jobPositionCategoryDicts: [],
      oneTypeDicts: [],
      props: {
        label: 'title',
        value: 'id',
        children: 'children'
      },
      // 省市区级联
      provincesAndMunicipalitiesProps: {
        label: 'name',
        value: 'code',
        children: 'children'
      },
      nameOfOrganizationLabel: '单位名称',
      locationOfTheUnitLabel: '单位所在地',
      backImages, //回显数据
      jyId: '',
      showPassBtn: true,
      showButton: false
    };
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.onRestWindow);
  },
  mounted() {
    this.onRestWindow();
    window.addEventListener('resize', this.onRestWindow);
    this.showButtonMethod();
    this.getDictData();
    if (this.$route.query.id) {
      this.type = this.$route.query.type;
      this.backRoute = this.$route.query.backRoute;
      this.qxform.id = this.$route.query.jyId;
      this.jyId = this.$route.query.jyId;
      // 20230918
      this.shform.id = this.$route.query.tId;
      this.shform.procInstId = this.$route.query.procInstId;
      this.shform.applyerUserid = this.$route.query.applyId;
      // 20230918
      this.getBysInfoById(this.$route.query.applyId);
      if (this.type == 3) {
        this.getJyqxData();
      }
      if (this.type == 4) {
        this.showPassBtn = false;
        this.getJyqxRecordData();
      }
    } else if (this.isZf == '1') {
      console.log(this.dataValue, 'this.dataValue');
      this.getBysInfoById(this.dataValue.userid);
      this.qxform.id = this.dataValue.id;
      this.getJyqxData();
      // this.qxform = this.form;
    } else {
      this.form = this.dataValue;
      // this.getBysData();
      this.getBysQxData();
    }
    console.log(this.qxform.dwszd,"单位行业");
  },
  methods: {
    showButtonMethod() {
      showButton().then(res => {
        if (res.success) {
          this.showButton = res.result;
        }
      })
    },
    onRestWindow() {
      this.quryLabelWidth = this.searchLabelWidth(120);
      this.quryLabelWidth2 = this.searchLabelWidth(140);
      this.labelWidth85 = this.searchLabelWidth(this.labelWidth85);
    },
    fillForeignName() {
      const selectedChineseName = this.qxform.jwxxzwmc;
      const matchedSchool = this.gwSchoolCodeList.find(item => item.chineseName === selectedChineseName);
      if (matchedSchool) {
        this.qxform.jwxxwwmc = matchedSchool.foreignName;
        this.qxform.lxgjdq = matchedSchool.gjOrDq;
      }
    },
    fillChineseName() {
      const selectedForeignName = this.qxform.jwxxwwmc;
      const matchedSchool = this.gwSchoolCodeList.find(item => item.foreignName === selectedForeignName);
      if (matchedSchool) {
        this.qxform.jwxxzwmc = matchedSchool.chineseName;
        this.qxform.lxgjdq = matchedSchool.gjOrDq;
      }
    },
    // region TODO 校验组织机构代码
    verify(value) {
      if (value.length == 15) {
        return false;
      } else {
        let reg = /(^[A-Za-z0-9]{18}$)/;
        return reg.test(value);
        //
        // let reg = /(^(?:(?![IOZSV])[\dA-Z]){2}\d{6}(?:(?![IOZSV])[\dA-Z]){10}$)|(^\d{15}$)/;
        // return reg.test(value)
        //
      }
    },
    storageApply(){
      console.log(this.qxform.dwszd);
      let arr= this.qxform.dwszd
      let qxform = {
        "address":arr[2],
        "code": this.qxform.tyshxycode,
        "contactPerson":this.qxform.dwlxr,
        "contactPhone": this.qxform.lxrdw,
        "industry": this.qxform.dwhy,
        "location": this.qxform.dwdz,
        "name": this.qxform.dwmc,
        "nature":this.qxform.dwxz,
        "sourceType": 0,
      }
      this.$confirm(`确认将${qxform.name}的单位信息申请入驻省库?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        awaitAdd(qxform).then(res=>{
          if (res.code==200){
            this.$message({
              type: 'success',
              message: '入驻成功!'
            });
          }else {
            this.$message({
              type: 'error',
              message: res.message
            });
          }
        })

      }).catch(() => {

      });
    },
    // 20230918
    passTask() {
      this.$refs.qxForm.validate(async valid => {
        if (valid) {
          this.passLoading = true;
          let lengeh = null;
          if (this.qxform.dwszd && this.qxform.dwszd !== null) {
            lengeh = this.qxform.dwszd.length - 1;
          }
          if (this.qxformRequired.zmcl && this.$refs.supportingMaterialRef.formFile.length > 0) {

            let zmcl = [];
            // for (const file of this.$refs.supportingMaterialRef.formFile) {
            //     // region TODO 上传证明材料
            //     const formData = new FormData();
            //     formData.append('file', file);
            //     const uploadResponse = await imageUploadDataApi(formData);
            //     if (uploadResponse.code == 200) {
            //         zmcl.push(uploadResponse.result)
            //     }
            // }
            for (let i = 0; i < this.$refs.supportingMaterialRef.formFile.length; i++) {
              let file = this.$refs.supportingMaterialRef.formFile[i];
              if (file.type) {
                console.log('文件类型', file);
                // region TODO 上传证明材料
                const formData = new FormData();
                formData.append('file', file);
                const uploadResponse = await imageUploadDataApi(formData);
                if (uploadResponse.code == 200) {
                  this.$refs.supportingMaterialRef.formFile[i] = uploadResponse.result;
                }
              }
            }
            zmcl = this.$refs.supportingMaterialRef.formFile;
            console.log('文件地址', zmcl);
            if (this.qxform.type == 11) {
              this.qxform.dwmc = this.qxform.jwxxzwmc;
            }
            console.log('证明材料', zmcl);
            const uploadResponse2 = await saveOrUpdate({
              ...this.qxform,
              id: this.jyId,
              zmcl: zmcl,
              dwszd1: lengeh === null ? '' : this.qxform.dwszd[lengeh]
            });
            pass(this.shform).then(res => {
              this.passLoading = false;
              if (res.success) {
                this.$Message.info(res.message);
                this.goBack();
              }
            });
            // if (uploadResponse2.code == 200) {
            //     await this.$router.go(-1)
            //     this.$Message.success('提交成功');
            // }

            // if (uploadResponse.code == 200) {
            //     this.destinationInformationForm.zmcl = uploadResponse.result;
            //     console.log('文件地址', uploadResponse);
            //     if (this.employmentCategory == 11) {
            //         this.destinationInformationForm.dwmc = this.destinationInformationForm.jwxxzwmc;
            //     }
            //
            //     const uploadResponse2 = await submitAPI({
            //         ...this.destinationInformationForm,
            //         type: this.employmentCategory,
            //         id: this.routeRow.id,
            //         procInstId: this.routeRow.procInstId,
            //         userid: this.routeRow.userid,
            //         eId: this.routeRow.eId,
            //         dwszd1: lengeh===null? '': this.destinationInformationForm.dwszd[lengeh]
            //     });
            //     if (uploadResponse2.code == 200) {
            //         await this.$router.push({ name: 'CareerDevelopmentAfterGraduation' });
            //         this.$Message.success('提交成功');
            //     }
            //     // endregion
            // }
          } else {
            const uploadResponse2 = await saveOrUpdate({
              ...this.qxform,
              id: this.jyId,
              dwszd1: lengeh === null ? '' : this.qxform.dwszd[lengeh]
            });
            pass(this.shform).then(res => {
              this.passLoading = false;
              if (res.success) {
                this.$Message.info(res.message);
                this.goBack();
              }
            });
            // if (uploadResponse2.code == 200) {
            //     this.btnLading = false;
            // }
          }
        }
      });


    },
    noPassTask() {
      this.noPassLoading = true;
      noPass(this.shform).then(res => {
        this.noPassLoading = false;
        if (res.success) {
          this.$Message.info(res.message);
          this.goBack();
        }
      });
    },
    backTask() {
      this.backLoading = true;
      back(this.shform).then(res => {
        this.backLoading = false;
        if (res.success) {
          this.$Message.info(res.message);
          this.goBack();
        }
      });
    },
    backCollegeTask() {
      this.backCollegeLoading = true;
      backCollege({
        procInstId: this.shform.procInstId,
        comment: this.shform.comment,
      }).then(res => {
        this.backCollegeLoading = false;
        this.$Message.info(res.message);
        this.goBack();
      });
    },
    // 20230918
    chooseOneType(val) {
      // this.qxform={};
      this.$nextTick(() => {
        if (val == 2) {
          this.nameOfOrganizationLabel = '学校名称';
          this.locationOfTheUnitLabel = '学校所在地';
        } else {
          this.nameOfOrganizationLabel = '单位名称';
          this.locationOfTheUnitLabel = '单位所在地';
        }
      });
      this.qxform.onetype = val;
      // console.log(val,"val")
      // if (val=="notEmployed "){
      //   this.required = false
      // }else{
      //   this.required = true
      // }
      this.getByQxs(val);
      // let res = await this.postRequest("/whereManage/getAll", {whereManageType: val});
      // if (res.success) {
      //   this.bysqxDicts = res.result;
      // }
    },
    chooseQx(e) {
      console.log(e, '111111');
    },
    async getJyqxRecordData() {
      // this.loading = true;
      let res = await this.postRequest('/bysJyqxRecord/getById', { id: this.$route.query.id });
      console.log('去向登记信息结果', res);
      if (res.success) {
        this.$nextTick(async () => {
          const year = '2023';
          let res1 = await this.postRequest('/gqQxCode/getTree', { dictMatch: res.result.onetype, version: year });
          if (res1.success) {
            console.log(res1.result, '就业类别');
            this.bysqxDicts = res1.result;
            judgmentRequired(res.result.onetype, res.result.type, this.qxform, this.qxformRequired, this.qxformPlaceholder, this.qxformIsShow);
          }
          // this.$refs.qxform.resetFields();
          updateVal(this.qxform, res.result);
          this.qxform.dwxz = res.result.dwxz;
          this.qxform.dwhy = res.result.dwhy;
          this.qxform.isBaseEmployment = res.result.isBaseEmployment;

          if (res.result.dwszd.indexOf(',') != -1) {
            let dwszd = res.result.dwszd.split(',') || '';
            this.qxform.dwszd = dwszd;
            // for (let item of dwszd) {
            //   console.log(item);
            //   this.qxform.dwszd.push(parseInt(item));
            // }
          } else {
            this.qxform.dwszd = [];
            this.qxform.dwszd.push(parseInt(res.result.dwszd));
          }
          try {
            if (this.qxform.zmcl) {
              this.qxform.zmcl = JSON.parse(crypto.decrypt(this.qxform.zmcl));
            }
          } catch (e) {
          }
          this.backImages = this.qxform.zmcl;
          this.areaNodes = getAreaTreeNodes(this.qxform.dwszd, this.areaCodeList);
        });
      }
    },
    async getJyqxData() {
      // this.loading = true;
      let res = await this.postRequest('/bysJyqxInfo/getById', { id: this.qxform.id });
      console.log('去向登记信息结果', res);
      if (res.success) {
        this.$nextTick(async () => {
          const year = '2023';
          let res1 = await this.postRequest('/gqQxCode/getTree', { dictMatch: res.result.onetype, version: year });
          if (res1.success) {
            this.bysqxDicts = res1.result;
            judgmentRequired(res.result.onetype, res.result.type, this.qxform, this.qxformRequired, this.qxformPlaceholder, this.qxformIsShow);
          }
          // this.$refs.qxform.resetFields();
          updateVal(this.qxform, res.result);
          this.qxform.dwxz = res.result.dwxz;
          this.qxform.dwhy = res.result.dwhy;
          this.qxform.isBaseEmployment = res.result.isBaseEmployment;
          if (this.qxform.lxrfax == null || this.qxform.lxrfax == 'null') {
            this.qxform.lxrfax == '';
          }
          if (this.qxform.dwyb == null || this.qxform.dwyb == 'null') {
            this.qxform.dwyb == '';
          }
          if (this.qxform.zzhxz == null || this.qxform.zzhxz == 'null') {
            this.qxform.zzhxz == '';
          }
          if (res.result.dwszd.indexOf(',') != -1) {
            let dwszd = res.result.dwszd.split(',') || [];
            this.qxform.dwszd =dwszd;
            // for (let item of dwszd) {
            //   console.log(item);
            //   this.qxform.dwszd.push(parseInt(item));
            // }
          } else {
            this.qxform.dwszd = [];
            this.qxform.dwszd.push(parseInt(res.result.dwszd));
            console.log('this.qxform22222', this.qxform);
          }
          try {
            if (this.qxform.zmcl) {
              this.qxform.zmcl = JSON.parse(crypto.decrypt(this.qxform.zmcl));
            }
          } catch (e) {
          }
          this.backImages = this.qxform.zmcl;
          this.areaNodes = getAreaTreeNodes(this.qxform.dwszd, this.areaCodeList);
          console.log('this.qxform', this.qxform.dwszd);
        });
      }
    },
    async getBysInfoById(id) {
      this.bysData = [];
      let res = await this.postRequest('/bysPersonInfo/getBysInfoById', { id: id });
      if (res.success) {
        this.form = res.result;
        // this.procInstId = res.result.procInstId;
        // this.showHistory = true;
      }
    },

    async getBysInfo() {
      this.bysData = [];
      let res = await this.postRequest('/bysPersonInfo/getBysInfo');
      if (res.success) {
        this.form = res.result;
        // this.procInstId = res.result.procInstId;
        // this.showHistory = true;
      }
    },
    async getBysQxData() {
      let res = await this.postRequest('/bysJyqxInfo/getBysQxInfo');
      if (res.success && res.result) {
        this.$refs.qxForm.resetFields();
        updateVal(this.qxform, res.result);
        console.log(this.qxform);
        if (this.qxform.zmcl) {
          this.qxform.zmcl = JSON.parse(crypto.decrypt(this.qxform.zmcl));
        }
        this.areaNodes = getAreaTreeNodes(this.qxform.dwszd, this.areaCodeList);
        this.chooseOneType(this.qxform.onetype);
        judgmentRequired(this.qxform.onetype, this.qxform.type, this.qxform, this.qxformRequired, this.qxformPlaceholder, this.qxformIsShow);
      }
    },
    getDictData() {
      // 单位所在地->取自数据库地区代码
      // this.postRequest("/areaCode/getAll").then(res => {
      //   if (res.success){
      //     this.dqCodeList = res.result
      //   }
      // })
      newProvincialDataApi().then(res => {
        let result = []
        if (res.success) {
          res.result.map(item=>{
            item.value = item.code
            item.label = item.name
            if(item.children){
              item.children.map(_item=>{
                _item.value = _item.code
                _item.label = _item.name
                if(_item.children){
                  _item.children.map(e=>{
                    e.value = e.code
                    e.label = e.name
                    delete e.children
                  })
                }
              })
            }
            result.push(item)
          })
          this.areaCodeList = result;
          // console.log(this.qxform.dwszd,"this.qxform.dwszd")
          this.areaNodes = getAreaTreeNodes(this.qxform.dwszd, this.areaCodeList);
        }
      });
      // 国外学校代码
      getAllGwschoolCodeList().then(res => {
        if (res.success) {
          this.gwSchoolCodeList = res.result;
        }
      });

      //毕业生就业状况
      obtainEmploymentStatusDataAPI()
          .then(res => {
            this.oneTypeDicts = res.result || [];
          })
          .catch(e => {
            console.log(e);
          });
      // getDictDataByType("where-manage-type").then(res => {
      //   if (res.success) {
      //     this.oneTypeDicts = res.result;
      //   }
      // })
      // this.getByQxs();

      //学历层次
      // getDictDataByType("unit-industry").then(res=>{
      //   if (res.success) {
      //     this.unitIndustryDicts = res.result;
      //   }
      // })

      //单位行业
      getDictDataByType('unit-industry').then(res => {
        if (res.success) {
          this.unitIndustryDicts = res.result;
        }
      });

      //单位性质
      getDictDataByType('unit-nature').then(res => {
        if (res.success) {
          this.unitNatureDicts = res?.result || [];
        }
      });
      //工作职位类别
      getDictDataByType('job-position-category').then(res => {
        if (res.success) {
          this.jobPositionCategoryDicts = res.result;
        }
      });
    },
    async getByQxs(val) {
      // const year = new Date().getFullYear()
      const year = '2023';
      let res = await this.postRequest('/gqQxCode/getTree', { dictMatch: val, version: year });
      if (res.success) {
        console.log(res.result, '就业类别');
        this.bysqxDicts = res.result;
        judgmentRequired(this.qxform.onetype, this.qxform.type, this.qxform, this.qxformRequired, this.qxformPlaceholder, this.qxformIsShow);
        // this.bysqxDicts = res.result.map(e=>{
        //   return {title:e.whereManageName,
        //     value:""+e.value
        //   }
        // });
      }
    },
    // 返回上一页
    goBack() {
      if (this.$route.query.id) {
        this.closeCurrentPage();
      } else {
        this.$emit('goBack');
      }
    },

    // 关闭当前页面
    closeCurrentPage() {
      this.$store.commit('removeTag', 'jyqx');
      sessionStorage.pageOpenedList = JSON.stringify(this.$store.state.app.pageOpenedList);
      // 返回到上一级
      // this.$router.go(-1)
      this.$router.push({
        name: this.backRoute
      });
    },
    // 提交
    onSubmit() {
      console.log(this.form, '===data');
    },
    edit() {
      this.$refs.qxForm.validate(valid => {
        if (valid) {
          this.editLoading = true;
          // 添加 避免编辑后传入id等数据 记得删除
          // delete this.form.id;
          // this.form.procDefId = this.procDefId;
          this.qxform.eId = this.form.eId;
          editJyqxInfo(this.qxform).then(res => {
            this.editLoading = false;
            if (res.success) {
              this.$Message.success('操作成功');
              this.goBack();
            }
          });
        }
      });
    },

    editAndApply() {
      this.$refs.qxForm.validate(valid => {
        if (valid) {
          this.editAndApplyLoading = true;
          // 添加 避免编辑后传入id等数据 记得删除
          // delete this.form.id;
          // this.form.procDefId = this.procDefId;
          this.qxform.eId = this.form.eId;
          editAndApplyJyqxInfo(this.qxform).then(res => {
            this.editAndApplyLoading = false;
            if (res.success) {
              this.$Message.success('操作成功');
              this.goBack();
            }
          });
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
//form表单间距统一修改
.ivu-form-item {
  margin-bottom: 0.01rem !important;
}

.formStyle {
  width: 800px;

  .formItem-input {
    width: 300px;
  }

  .formItem-input-area {
    width: 360px;
  }
}

.head-box {
  height: 50px;
}

.ch85 {
  height: 720px;
}

.cfont12 {
  font-size: 12px;
}

.cw630 {
  width: 630px
}

.cml {
  margin-left: 25px
}
</style>
